package se.olli.jonsered;

import java.util.ArrayList;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;

public class MemoryAdapter extends BaseAdapter {
    private Integer[] images = {		// Array of images
    		R.drawable.memory_back, R.drawable.memory_back, R.drawable.memory_back, 
    		R.drawable.memory_back, R.drawable.memory_back, R.drawable.memory_back,
    		R.drawable.memory_back, R.drawable.memory_back, R.drawable.memory_back,
    		R.drawable.memory_back, R.drawable.memory_back, R.drawable.memory_back
    };
    private ArrayList<ImageView> imViews = new ArrayList<ImageView>();
    private Context mContext;

    public MemoryAdapter(Context c) {
        mContext = c;
    }
    
    public void setImage(int position, int resId) {
    	images[position] = resId;
    }
    
	public int getCount() {
		return images.length;
	}

	public Object getItem(int position) {
		return imViews.get(position+1);
	}

	public long getItemId(int position) {
		return position;
	}

	 public View getView(int position, View convertView, ViewGroup parent) {
	        ImageView imageView;
	        if (convertView == null) {
	            imageView = new ImageView(mContext);
	           // LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
	           // 		LinearLayout.LayoutParams.FILL_PARENT, 
	           // 		LinearLayout.LayoutParams.FILL_PARENT);
	            
	            imageView.setLayoutParams(new GridView.LayoutParams(150, 150));
	            imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
	            imageView.setPadding(4, 4, 4, 4);
	        } else {
	            imageView = (ImageView) convertView;
	        }
	        //Log.d("IMAGE", ""+images[position]+" "+position);
	        //imageView.setImageResource(imgArray.get(position));
	        imageView.setImageResource(images[position]);
	        imViews.add(imageView);
	        return imageView;
	    }

}
